package elijah.eupdater;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import elijah.eupdater.bean.UpdaterConfig;

public class Eupdater {
    private static volatile Eupdater mInstance;
    private UpdaterConfig config;
    private Context context;

    private Eupdater() {
    }

    public static Eupdater get() {
        if (mInstance == null) {
            synchronized (Eupdater.class) {
                if (mInstance == null) {
                    mInstance = new Eupdater();
                }
            }
        }
        return mInstance;
    }

    public void init(Context context, UpdaterConfig config) {
        this.context = context;
        this.config = config;
        Log.e("TAG", "init: ");
        Intent intent = new Intent(context, UpdateService.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startService(intent);
    }

    public UpdaterConfig getConfig() {
        return config == null ? new UpdaterConfig() : config;
    }

    public Context getContext() {
        return context;
    }
}
